import React, { Component } from 'react';
import css from './index.less';
import FilterSearch from '@/components/FilterSearch';
import TableList from '@/components/TableList';
import EditModal from '@/components/EditModal';
import { Button, Divider } from 'antd';
import { connect } from 'dva';
import { timeFormat } from '@/utils/common';
import Status from '@/pages/components/Status';

type State = {
  selectProject: any;
};
type Props = {
  dispatch: Function;
};
class Department extends Component<Props> {
  state: State = {
    selectProject: {},
  };
  table = null;

  filters = [
    {
      key: 'serviceTypeUuid',
      type: 'select',
      label: '项目类型',
      asyncopt: {
        url: '/api/data/v1/getDataList',
        data: {
          code: 'service',
        },
      },
    },
    {
      key: 'approveStatus',
      type: 'select',
      label: '审批状态',
      options: this.props.dict.approveStatus,
    },
    {
      key: 'no',
      type: 'input',
      label: '项目ID',
    },
    {
      key: 'name',
      type: 'input',
      label: '项目名称',
    },
    {
      key: 'orgUnitName',
      type: 'input',
      label: '业主单位',
    },
  ];
  columns = [
    { title: '项目ID', dataIndex: 'no', width: 150 },
    {
      title: '项目名称',
      dataIndex: 'name',
      render: (text, data) => (
        <Button type="link" onClick={() => this.goDetail(data, true)}>
          {text}
        </Button>
      ),
    },
    {
      title: '申报日期',
      dataIndex: 'createTime',
      width: 180,
      format: 'YYYY-MM-DD',
    },
    { title: '项目性质', dataIndex: 'buildType' },
    { title: '项目类型', dataIndex: ['serviceTypeData', 'display'] },
    { title: '行业领域', dataIndex: ['professionData', 'display'] },
    { title: '总投资（万元）', dataIndex: 'totalInvestment' },
    {
      title: '拟开建年份',
      dataIndex: 'expectStartYear',
      render: text => `${text}年`,
    },
  ];
  goDetail = (data, readOnly) => {
    const url = `projectCollect/storeCollect/edit?id=${data.uuid ||
      ''}&readOnly=${readOnly || ''}&fromType=5`;
    this.props.dispatch({
      type: '$router/forward',
      payload: {
        url,
      },
    });
  };

  render() {
    const { selectProject } = this.state;
    return (
      <div>
        <FilterSearch
          filters={this.filters}
          onSearch={val => this.table.fetch(val)}
        ></FilterSearch>
        <TableList
          post
          rowKey="id"
          onRef={c => {
            this.table = c;
          }}
          columns={this.columns}
          source="/api/project/store/v1/storeProject/query"
        />
      </div>
    );
  }
}

export default connect(state => state.base)(Department);
